package com.example.mvvmdemo.home.ui;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModelKt;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mvvmdemo.R;
import com.example.mvvmdemo.databinding.FragmentMainBinding;
import com.example.mvvmdemo.home.data.MainViewModel;
import com.example.mvvmdemo.home.paging.DeviceAdapter;
import com.example.mvvmdemo.home.paging.DeviceComparator;
import com.example.mvvmlibrary.base.data.BaseViewModel;
import com.example.mvvmlibrary.base.fragment.BaseDataBindingFragment;

import kotlinx.coroutines.CoroutineScope;

/**
 * created by tl
 * created at 2020/9/2
 */
public class MainFragment extends BaseDataBindingFragment<FragmentMainBinding, BaseViewModel> {

    public static final String TAG = "MainFragment";
    private MainViewModel viewModel;

    public static MainFragment newInstance() {

        Bundle args = new Bundle();

        MainFragment fragment = new MainFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        MainViewBindingActivity activity = (MainViewBindingActivity) context;
        viewModel = activity.getViewModel();
    }

    @Override
    protected int getVariableId() {
        return 0;
    }

    @Override
    protected int getLayoutID() {
        return R.layout.fragment_main;
    }

    @Override
    protected void initialization() {
        DeviceAdapter deviceAdapter = new DeviceAdapter( R.layout.item_device, new DeviceComparator());
        binding.mainRv.addItemDecoration(new DividerItemDecoration(getContext(), RecyclerView.VERTICAL));
        binding.mainRv.setAdapter(deviceAdapter);
    }

}
